package com.sh.personnel.mapper;

import com.sh.personnel.domain.ITbMenu;
import com.sh.personnel.vo.dto.MenuDto;
import com.sh.personnel.vo.dto.MenuTreeDto;
import com.sh.personnel.vo.dto.SelectTreeDto;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 林思浩
 * @date 2020/03/13 14:20
 */
@Repository
public interface IMenuMapper {

    List<MenuTreeDto> getMenuAllInRoleId(@Param("ids") List<Integer> roleIds);

    //获取所有菜单的id/name
    List<SelectTreeDto> findMenuAllIDAndName(String type);

    //获取菜单列表
    List<MenuDto> findMenuAllList(String key);

    //添加菜单
    @Insert("INSERT INTO tb_menu (permission, name, path, component, createtime, parentid, sort, type, icon)" +
            " VALUES" +
            " (#{permission}, #{name}, #{path}, #{component}, #{createtime}, #{parentid}, #{sort}, #{type}, #{icon})")
    int insertMenu(ITbMenu menu);

    //查看菜单
    @Select("SELECT t1.*, t2.name AS parentName FROM tb_menu t1 LEFT JOIN tb_menu t2" +
            " ON t1.parentid = t2.id" +
            " WHERE t1.id = #{id}")
    ITbMenu findMenuById(String id);

    //更新菜单
    @Update("UPDATE tb_menu SET name=#{name}, permission=#{permission}, path=#{path}, component=#{component}," +
            " parentid=#{parentid}, sort=#{sort}, type=#{type}, icon=#{icon}" +
            " WHERE id = #{id}")
    int updateMenuById(ITbMenu menu);

    //删除菜单
    @Delete("DELETE FROM tb_menu WHERE id = #{id}")
    int deleteMenuById(String id);


}
